package edu.njust.service;

import edu.njust.dao.ComputerMapper;
import edu.njust.dao.ReservationMapper;
import edu.njust.dao.UserMapper;
import edu.njust.pojo.Computer;
import edu.njust.pojo.ComputerRoom;

import java.util.List;

public class ComputerServiceImpl implements ComputerService {

    private UserMapper userMapper;

    public UserMapper getUserMapper(){
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    private ComputerMapper computerMapper;

    public ComputerMapper getComputerMapper(){
        return computerMapper;
    }

    public void setComputerMapper(ComputerMapper computerMapper) {
        this.computerMapper = computerMapper;
    }

    private ReservationMapper reservationMapper;

    public ReservationMapper getReservationMapper(){
        return reservationMapper;
    }

    public void setReservationMapper(ReservationMapper reservationMapper) {
        this.reservationMapper = reservationMapper;
    }
    @Override
    public List<ComputerRoom> getAllComputerRoom() {
        return computerMapper.getAllComputerRoom();
    }

    @Override
    public List<Computer> getAllComputer(String id){
        return computerMapper.getComputerListById(id);
    }

    @Override
    public boolean getComputerState(String room_id, String computer_id) {
        Computer computer = computerMapper.getComputerByRoomIdAndComputerId(room_id, computer_id);
        System.out.println(computer);
        return computer.isUsable();
    }

    @Override
    public Integer modifyComputerState(String room_id, String computer_id, boolean new_state){
        Computer computer = new Computer(computer_id,room_id,new_state);
        computerMapper.update(computer);
        ComputerRoom computerRoom = computerMapper.getComputerRoomById(room_id);
        if(new_state){
            computerRoom.changeUsable(1);
        }else{
            computerRoom.changeUsable(-1);
        }
        return computerMapper.updateRoom(computerRoom);
    }


}
